﻿using JGSoft.U9CRTAPIEX.DTOs.RequestDTOs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UFIDA.U9.Base;
using UFIDA.U9.Base.DTOs;
using UFIDA.U9.Base.PropertyTypes;
using UFIDA.U9.CBO.DTOs;
using UFIDA.U9.CBO.Pub.Controller;
using UFIDA.U9.CBO.Pub.Controller.Proxy;
using UFIDA.U9.CBO.SCM.Item;

namespace JGSoft.U9CRTAPIEX.DTOs
{
    public class ToolUtils
    {
		public static string GetStr(object obj)
		{
			string str = string.Empty;
			if (obj != null && obj != DBNull.Value)
			{
				str = obj.ToString();
			}
			return str;
		}

		// Token: 0x060000D8 RID: 216 RVA: 0x0000DC90 File Offset: 0x0000BE90
		public static decimal GetDecimal(object obj)
		{
			decimal rs = 0m;
			if (obj != DBNull.Value && obj != null)
			{
				rs = Convert.ToDecimal(obj);
			}
			return rs;
		}

		// Token: 0x060000D9 RID: 217 RVA: 0x0000DCC8 File Offset: 0x0000BEC8
		public static long GetInt64(object obj)
		{
			long rs = 0L;
			if (obj != DBNull.Value && obj != null)
			{
				rs = Convert.ToInt64(obj);
			}
			return rs;
		}

		// Token: 0x060000DA RID: 218 RVA: 0x0000DD50 File Offset: 0x0000BF50
		public static string ConvertDateTimeJsonStr(string jsonStr)
		{
			jsonStr = Regex.Replace(jsonStr, "\\\\/Date\\((\\d+)\\)\\\\/", delegate (Match match)
			{
				DateTime dt = new DateTime(1970, 1, 1);
				dt = dt.AddMilliseconds((double)long.Parse(match.Groups[1].Value));
				dt = dt.ToLocalTime();
				return dt.ToString("yyyy-MM-dd HH:mm:ss");
			});
			jsonStr = Regex.Replace(jsonStr, "\\\\/Date\\((-\\d+)\\)\\\\/", "");
			return jsonStr;
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="fromDTO"></param>
		/// <returns></returns>
		// Token: 0x060000DB RID: 219 RVA: 0x0000DDA4 File Offset: 0x0000BFA4
		public static CommonArchiveDataDTOData CommonArchiveDataDTODataTrans(CommonArchiveDataDTOData fromDTO)
		{
			CommonArchiveDataDTOData dto = null;
			if (fromDTO != null && (fromDTO.ID > 0L || fromDTO.Code != string.Empty))
			{
				dto = new CommonArchiveDataDTOData();
				dto.ID = fromDTO.ID;
				dto.Code = fromDTO.Code;
				dto.Name = fromDTO.Name;
			}
			return dto;
		}

		// Token: 0x060000DC RID: 220 RVA: 0x0000DE14 File Offset: 0x0000C014
		public static List<CommonArchiveDataDTOData> CommonArchiveDataDTODataListTrans(List<CommonArchiveDataDTOData> fromDTOs)
		{
			List<CommonArchiveDataDTOData> dtos = null;
			if (fromDTOs != null && fromDTOs.Count > 0)
			{
				dtos = new List<CommonArchiveDataDTOData>();
				foreach (CommonArchiveDataDTOData fromDTO in fromDTOs)
				{
					dtos.Add(ToolUtils.CommonArchiveDataDTODataTrans(fromDTO));
				}
			}
			return dtos;
		}

		// Token: 0x060000DD RID: 221 RVA: 0x0000DE98 File Offset: 0x0000C098
		public static IDCodeNameDTOData IDCodeNameDTODataTrans(CommonArchiveDataDTOData fromDTO)
		{
			IDCodeNameDTOData dto = null;
			if (fromDTO != null)
			{
				dto = new IDCodeNameDTOData();
				dto.ID = fromDTO.ID;
				dto.Code = fromDTO.Code;
				dto.Name = fromDTO.Name;
			}
			return dto;
		}

		/// <summary>
		/// DoubleQuantity转换为DoubleQuantityData
		/// </summary>
		/// <param name="Qty">双数量</param>
		/// <returns></returns>
		// Token: 0x060000DE RID: 222 RVA: 0x0000DEE4 File Offset: 0x0000C0E4
		public static DoubleQuantityData ConvertDoubleQuantityToData(DoubleQuantity Qty)
		{
			DoubleQuantityData result;
			if (Qty == null)
			{
				result = new DoubleQuantityData();
			}
			else
			{
				DoubleQuantityData _RejectQty = new DoubleQuantityData();
				_RejectQty.Amount1 = Qty.Amount1;
				_RejectQty.Amount2 = Qty.Amount2;
				if (Qty.UOM1 != null)
				{
					_RejectQty.UOM1.UOMMain_SKey = Qty.UOM1.UOMMain;
					_RejectQty.UOM1.UOMSub_SKey = Qty.UOM1.UOMSub;
					_RejectQty.UOM1.Rate = Qty.UOM1.Rate;
				}
				if (Qty.UOM2 != null)
				{
					_RejectQty.UOM2.UOMMain_SKey = Qty.UOM2.UOMMain;
					_RejectQty.UOM2.UOMSub_SKey = Qty.UOM2.UOMSub;
					_RejectQty.UOM2.Rate = Qty.UOM2.Rate;
				}
				result = _RejectQty;
			}
			return result;
		}

		/// <summary>
		/// 根据Code获取实体ID
		/// </summary>
		/// <param name="entityCode"></param>
		/// <param name="entityType"></param>
		/// <returns></returns>
		// Token: 0x060000DF RID: 223 RVA: 0x0000DFD8 File Offset: 0x0000C1D8
		public static long GetDocID(string entityCode, string entityType)
		{
			long entityID = -1L;
			if (!string.IsNullOrEmpty(entityCode))
			{
				ArchiveDataInfoData aDTO = new QueryArchiveDataSVProxy
				{
					OrgID = Context.LoginOrg.ID,
					Code = entityCode,
					EntityType = entityType
				}.Do();
				if (aDTO != null && aDTO.EntityKey != null)
				{
					entityID = aDTO.EntityKey.ID;
				}
			}
			return entityID;
		}

		/// <summary>
		/// 实体扩展字段转换为标准实体扩展字段DTO
		/// </summary>
		/// <param name="rData"></param>
		/// <returns></returns>
		// Token: 0x060000E0 RID: 224 RVA: 0x0000E054 File Offset: 0x0000C254
		public static UFIDA.U9.Base.FlexField.DescFlexField.DescFlexSegmentsData ConvertDescFlexFieldToData(DescFlexFieldRData rData)
		{
			UFIDA.U9.Base.FlexField.DescFlexField.DescFlexSegmentsData descFlexField = new UFIDA.U9.Base.FlexField.DescFlexField.DescFlexSegmentsData();
			UFIDA.U9.Base.FlexField.DescFlexField.DescFlexSegmentsData result;
			if (rData == null)
			{
				result = descFlexField;
			}
			else
			{
				descFlexField.PubDescSeg1 = rData.PubDescSeg1;
				descFlexField.PubDescSeg2 = rData.PubDescSeg2;
				descFlexField.PubDescSeg3 = rData.PubDescSeg3;
				descFlexField.PubDescSeg4 = rData.PubDescSeg4;
				descFlexField.PubDescSeg5 = rData.PubDescSeg5;
				descFlexField.PubDescSeg6 = rData.PubDescSeg6;
				descFlexField.PubDescSeg7 = rData.PubDescSeg7;
				descFlexField.PubDescSeg8 = rData.PubDescSeg8;
				descFlexField.PubDescSeg9 = rData.PubDescSeg9;
				descFlexField.PubDescSeg10 = rData.PubDescSeg10;
				descFlexField.PubDescSeg11 = rData.PubDescSeg11;
				descFlexField.PubDescSeg12 = rData.PubDescSeg12;
				descFlexField.PubDescSeg13 = rData.PubDescSeg13;
				descFlexField.PubDescSeg14 = rData.PubDescSeg14;
				descFlexField.PubDescSeg15 = rData.PubDescSeg15;
				descFlexField.PubDescSeg16 = rData.PubDescSeg16;
				descFlexField.PubDescSeg17 = rData.PubDescSeg17;
				descFlexField.PubDescSeg18 = rData.PubDescSeg18;
				descFlexField.PubDescSeg19 = rData.PubDescSeg19;
				descFlexField.PubDescSeg20 = rData.PubDescSeg20;
				descFlexField.PubDescSeg21 = rData.PubDescSeg21;
				descFlexField.PubDescSeg22 = rData.PubDescSeg22;
				descFlexField.PubDescSeg23 = rData.PubDescSeg23;
				descFlexField.PubDescSeg24 = rData.PubDescSeg24;
				descFlexField.PubDescSeg25 = rData.PubDescSeg25;
				descFlexField.PubDescSeg26 = rData.PubDescSeg26;
				descFlexField.PubDescSeg27 = rData.PubDescSeg27;
				descFlexField.PubDescSeg28 = rData.PubDescSeg28;
				descFlexField.PubDescSeg29 = rData.PubDescSeg29;
				descFlexField.PubDescSeg30 = rData.PubDescSeg30;
				descFlexField.PubDescSeg31 = rData.PubDescSeg31;
				descFlexField.PubDescSeg32 = rData.PubDescSeg32;
				descFlexField.PubDescSeg33 = rData.PubDescSeg33;
				descFlexField.PubDescSeg34 = rData.PubDescSeg34;
				descFlexField.PubDescSeg35 = rData.PubDescSeg35;
				descFlexField.PubDescSeg36 = rData.PubDescSeg36;
				descFlexField.PubDescSeg37 = rData.PubDescSeg37;
				descFlexField.PubDescSeg38 = rData.PubDescSeg38;
				descFlexField.PubDescSeg39 = rData.PubDescSeg39;
				descFlexField.PubDescSeg40 = rData.PubDescSeg40;
				descFlexField.PubDescSeg41 = rData.PubDescSeg41;
				descFlexField.PubDescSeg42 = rData.PubDescSeg42;
				descFlexField.PubDescSeg43 = rData.PubDescSeg43;
				descFlexField.PubDescSeg44 = rData.PubDescSeg44;
				descFlexField.PubDescSeg45 = rData.PubDescSeg45;
				descFlexField.PubDescSeg46 = rData.PubDescSeg46;
				descFlexField.PubDescSeg47 = rData.PubDescSeg47;
				descFlexField.PubDescSeg48 = rData.PubDescSeg48;
				descFlexField.PubDescSeg49 = rData.PubDescSeg49;
				descFlexField.PubDescSeg50 = rData.PubDescSeg50;
				descFlexField.PrivateDescSeg1 = rData.PrivateDescSeg1;
				descFlexField.PrivateDescSeg2 = rData.PrivateDescSeg2;
				descFlexField.PrivateDescSeg3 = rData.PrivateDescSeg3;
				descFlexField.PrivateDescSeg4 = rData.PrivateDescSeg4;
				descFlexField.PrivateDescSeg5 = rData.PrivateDescSeg5;
				descFlexField.PrivateDescSeg6 = rData.PrivateDescSeg6;
				descFlexField.PrivateDescSeg7 = rData.PrivateDescSeg7;
				descFlexField.PrivateDescSeg8 = rData.PrivateDescSeg8;
				descFlexField.PrivateDescSeg9 = rData.PrivateDescSeg9;
				descFlexField.PrivateDescSeg10 = rData.PrivateDescSeg10;
				descFlexField.PrivateDescSeg11 = rData.PrivateDescSeg11;
				descFlexField.PrivateDescSeg12 = rData.PrivateDescSeg12;
				descFlexField.PrivateDescSeg13 = rData.PrivateDescSeg13;
				descFlexField.PrivateDescSeg14 = rData.PrivateDescSeg14;
				descFlexField.PrivateDescSeg15 = rData.PrivateDescSeg15;
				descFlexField.PrivateDescSeg16 = rData.PrivateDescSeg16;
				descFlexField.PrivateDescSeg17 = rData.PrivateDescSeg17;
				descFlexField.PrivateDescSeg18 = rData.PrivateDescSeg18;
				descFlexField.PrivateDescSeg19 = rData.PrivateDescSeg19;
				descFlexField.PrivateDescSeg20 = rData.PrivateDescSeg20;
				descFlexField.PrivateDescSeg21 = rData.PrivateDescSeg21;
				descFlexField.PrivateDescSeg22 = rData.PrivateDescSeg22;
				descFlexField.PrivateDescSeg23 = rData.PrivateDescSeg23;
				descFlexField.PrivateDescSeg24 = rData.PrivateDescSeg24;
				descFlexField.PrivateDescSeg25 = rData.PrivateDescSeg25;
				descFlexField.PrivateDescSeg26 = rData.PrivateDescSeg26;
				descFlexField.PrivateDescSeg27 = rData.PrivateDescSeg27;
				descFlexField.PrivateDescSeg28 = rData.PrivateDescSeg28;
				descFlexField.PrivateDescSeg29 = rData.PrivateDescSeg29;
				descFlexField.PrivateDescSeg30 = rData.PrivateDescSeg30;
				result = descFlexField;
			}
			return result;
		}

		// Token: 0x060000E1 RID: 225 RVA: 0x0000E490 File Offset: 0x0000C690
		public static DescFlexFieldRData ConvertDataToDescFlexField(UFIDA.U9.Base.FlexField.DescFlexField.DescFlexSegmentsData rData)
		{
			DescFlexFieldRData descFlexField = new DescFlexFieldRData();
			DescFlexFieldRData result;
			if (rData == null)
			{
				result = descFlexField;
			}
			else
			{
				descFlexField.PubDescSeg1 = rData.PubDescSeg1;
				descFlexField.PubDescSeg2 = rData.PubDescSeg2;
				descFlexField.PubDescSeg3 = rData.PubDescSeg3;
				descFlexField.PubDescSeg4 = rData.PubDescSeg4;
				descFlexField.PubDescSeg5 = rData.PubDescSeg5;
				descFlexField.PubDescSeg6 = rData.PubDescSeg6;
				descFlexField.PubDescSeg7 = rData.PubDescSeg7;
				descFlexField.PubDescSeg8 = rData.PubDescSeg8;
				descFlexField.PubDescSeg9 = rData.PubDescSeg9;
				descFlexField.PubDescSeg10 = rData.PubDescSeg10;
				descFlexField.PubDescSeg11 = rData.PubDescSeg11;
				descFlexField.PubDescSeg12 = rData.PubDescSeg12;
				descFlexField.PubDescSeg13 = rData.PubDescSeg13;
				descFlexField.PubDescSeg14 = rData.PubDescSeg14;
				descFlexField.PubDescSeg15 = rData.PubDescSeg15;
				descFlexField.PubDescSeg16 = rData.PubDescSeg16;
				descFlexField.PubDescSeg17 = rData.PubDescSeg17;
				descFlexField.PubDescSeg18 = rData.PubDescSeg18;
				descFlexField.PubDescSeg19 = rData.PubDescSeg19;
				descFlexField.PubDescSeg20 = rData.PubDescSeg20;
				descFlexField.PubDescSeg21 = rData.PubDescSeg21;
				descFlexField.PubDescSeg22 = rData.PubDescSeg22;
				descFlexField.PubDescSeg23 = rData.PubDescSeg23;
				descFlexField.PubDescSeg24 = rData.PubDescSeg24;
				descFlexField.PubDescSeg25 = rData.PubDescSeg25;
				descFlexField.PubDescSeg26 = rData.PubDescSeg26;
				descFlexField.PubDescSeg27 = rData.PubDescSeg27;
				descFlexField.PubDescSeg28 = rData.PubDescSeg28;
				descFlexField.PubDescSeg29 = rData.PubDescSeg29;
				descFlexField.PubDescSeg30 = rData.PubDescSeg30;
				descFlexField.PubDescSeg31 = rData.PubDescSeg31;
				descFlexField.PubDescSeg32 = rData.PubDescSeg32;
				descFlexField.PubDescSeg33 = rData.PubDescSeg33;
				descFlexField.PubDescSeg34 = rData.PubDescSeg34;
				descFlexField.PubDescSeg35 = rData.PubDescSeg35;
				descFlexField.PubDescSeg36 = rData.PubDescSeg36;
				descFlexField.PubDescSeg37 = rData.PubDescSeg37;
				descFlexField.PubDescSeg38 = rData.PubDescSeg38;
				descFlexField.PubDescSeg39 = rData.PubDescSeg39;
				descFlexField.PubDescSeg40 = rData.PubDescSeg40;
				descFlexField.PubDescSeg41 = rData.PubDescSeg41;
				descFlexField.PubDescSeg42 = rData.PubDescSeg42;
				descFlexField.PubDescSeg43 = rData.PubDescSeg43;
				descFlexField.PubDescSeg44 = rData.PubDescSeg44;
				descFlexField.PubDescSeg45 = rData.PubDescSeg45;
				descFlexField.PubDescSeg46 = rData.PubDescSeg46;
				descFlexField.PubDescSeg47 = rData.PubDescSeg47;
				descFlexField.PubDescSeg48 = rData.PubDescSeg48;
				descFlexField.PubDescSeg49 = rData.PubDescSeg49;
				descFlexField.PubDescSeg50 = rData.PubDescSeg50;
				descFlexField.PrivateDescSeg1 = rData.PrivateDescSeg1;
				descFlexField.PrivateDescSeg2 = rData.PrivateDescSeg2;
				descFlexField.PrivateDescSeg3 = rData.PrivateDescSeg3;
				descFlexField.PrivateDescSeg4 = rData.PrivateDescSeg4;
				descFlexField.PrivateDescSeg5 = rData.PrivateDescSeg5;
				descFlexField.PrivateDescSeg6 = rData.PrivateDescSeg6;
				descFlexField.PrivateDescSeg7 = rData.PrivateDescSeg7;
				descFlexField.PrivateDescSeg8 = rData.PrivateDescSeg8;
				descFlexField.PrivateDescSeg9 = rData.PrivateDescSeg9;
				descFlexField.PrivateDescSeg10 = rData.PrivateDescSeg10;
				descFlexField.PrivateDescSeg11 = rData.PrivateDescSeg11;
				descFlexField.PrivateDescSeg12 = rData.PrivateDescSeg12;
				descFlexField.PrivateDescSeg13 = rData.PrivateDescSeg13;
				descFlexField.PrivateDescSeg14 = rData.PrivateDescSeg14;
				descFlexField.PrivateDescSeg15 = rData.PrivateDescSeg15;
				descFlexField.PrivateDescSeg16 = rData.PrivateDescSeg16;
				descFlexField.PrivateDescSeg17 = rData.PrivateDescSeg17;
				descFlexField.PrivateDescSeg18 = rData.PrivateDescSeg18;
				descFlexField.PrivateDescSeg19 = rData.PrivateDescSeg19;
				descFlexField.PrivateDescSeg20 = rData.PrivateDescSeg20;
				descFlexField.PrivateDescSeg21 = rData.PrivateDescSeg21;
				descFlexField.PrivateDescSeg22 = rData.PrivateDescSeg22;
				descFlexField.PrivateDescSeg23 = rData.PrivateDescSeg23;
				descFlexField.PrivateDescSeg24 = rData.PrivateDescSeg24;
				descFlexField.PrivateDescSeg25 = rData.PrivateDescSeg25;
				descFlexField.PrivateDescSeg26 = rData.PrivateDescSeg26;
				descFlexField.PrivateDescSeg27 = rData.PrivateDescSeg27;
				descFlexField.PrivateDescSeg28 = rData.PrivateDescSeg28;
				descFlexField.PrivateDescSeg29 = rData.PrivateDescSeg29;
				descFlexField.PrivateDescSeg30 = rData.PrivateDescSeg30;
				result = descFlexField;
			}
			return result;
		}

		/// <summary>
		/// 料品信息字段转换为标准料品信息字段DTO
		/// </summary>
		/// <param name="RData"></param>
		/// <returns></returns>
		// Token: 0x060000E2 RID: 226 RVA: 0x0000E8CC File Offset: 0x0000CACC
		public static ItemInfoData ToItemInfoData(ItemInfoRData RData)
		{
			return new ItemInfoData
			{
				ItemID = RData.ItemID,
				ItemCode = RData.ItemCode,
				ItemName = RData.ItemName,
				ItemGrade = RData.ItemGrade,
				ItemPotency = RData.ItemPotency,
				ItemVersion = RData.ItemVersion
			};
		}

		// Token: 0x060000E3 RID: 227 RVA: 0x0000E934 File Offset: 0x0000CB34
		public static ItemInfoRData FromItemInfoData(ItemInfoData data)
		{
			return new ItemInfoRData
			{
				ItemID = data.ItemID,
				ItemCode = data.ItemCode,
				ItemName = data.ItemName,
				ItemGrade = data.ItemGrade,
				ItemPotency = data.ItemPotency,
				ItemVersion = data.ItemVersion
			};
		}

	
	}
}
